﻿Public Class clsDieClean

    ''' <summary>
    ''' T_Alarm_A51_DieCleanを更新
    ''' </summary>
    ''' <param name="EquipNo">設備No.</param>
    ''' <param name="shotNum">SHOT数</param>
    Public Sub updDieClean(EquipNo As String, shotNum As Integer, NUMFLAG As Integer)

        Dim szSql As String = ""

        szSql &= "UPDATE per.T_Alarm_A51_DieClean SET "
        szSql &= " SumSHOT = SumSHOT +  " & shotNum
        szSql &= " ,NUMFLAG = " & NUMFLAG

        szSql &= " WHERE  EquipNo = '" & EquipNo & "' AND "
        szSql &= " USEFLAG = 1 "

        DBacs.ExecuteUpdateSql(szSql, -1)

    End Sub

    ''' <summary>
    ''' 累計SHOT数を検索
    ''' </summary>
    ''' <param name="EquipNo">設備No.</param>
    Public Sub selDieCleanSPEC(EquipNo As String, ByRef sumShotValue As Integer,
                                    ByRef LSPECVALUE As Integer, ByRef SPECVALUE As Integer)
        Dim szSql As String = ""
        szSql &= "SELECT EQUIPNO,SumSHOT,LSPECVALUE ,SPECVALUE "
        szSql &= "FROM PER.T_ALARM_A51_DIECLEAN "
        szSql &= "WHERE EQUIPNO ='" & EquipNo & "' AND "
        szSql &= "USEFLAG = 1 order by sumSHOT DESC "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            sumShotValue = 0
            LSPECVALUE = 0
            SPECVALUE = 0
        Else
            sumShotValue = dt(0)("SumSHOT")
            LSPECVALUE = dt(0)("LSPECVALUE")
            SPECVALUE = dt(0)("SPECVALUE")
        End If

    End Sub
    ''' <summary>
    ''' 規格値を取得する
    ''' </summary>
    ''' <param name="EquipNo">設備No.</param>
    ''' <returns>規格値</returns>
    Public Function selSpecValue(EquipNo As String) As Integer
        Dim SpecValue As Integer
        Dim szSql As String = ""
        szSql &= "SELECT SpecValue "
        szSql &= "FROM PER.T_Alarm_A51_DieClean "
        szSql &= "WHERE EQUIPNO = '" & EquipNo & "' AND "
        szSql &= "USEFLAG = 1 "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            SpecValue = 0
        Else
            SpecValue = dt(0)(0)
        End If
        Return SpecValue
    End Function

    Public Function selSpecDt(EquipNo As String) As DataTable

        Dim szSql As String = ""
        szSql &= "SELECT * "
        szSql &= "FROM PER.T_Alarm_A51_DieClean "
        szSql &= "WHERE EQUIPNO = '" & EquipNo & "' AND "
        szSql &= "USEFLAG = 1 "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            Return New DataTable
        End If
        Return dt
    End Function
    ''' <summary>
    ''' T_A51_DieCleanRecordにデータ新規
    ''' </summary>
    ''' <param name="EquipNo">設備No.</param>
    ''' <param name="MouldGroupNo">モールド組No.</param>
    ''' <param name="PKG">PKG</param>
    ''' <param name="LotNo">LotNo.</param>
    ''' <param name="SHOTNum">SHOT数</param>
    ''' <param name="sumSHOTNum">累計SHOT数</param>
    Public Sub insertRecord(EquipNo As String, MouldGroupNo As String, PKG As String, LotNo As String, SHOTNum As Integer, sumSHOTNum As Integer)
        Dim szSql As String = ""
        Dim objDbCondData As New clsDbCondData

        szSql = ""
        szSql &= "INSERT INTO PER.T_A51_DieCleanRecord (EquipNo,MouldGroupNo,insertDate,PKG,InClear,LotNo,SHOT,SumSHOT) "
        szSql &= "VALUES ( "
        szSql &= String.Format("'{0}', '{1}', '{2}','{3}','{4}','{5}',{6},{7}",
                                EquipNo, MouldGroupNo, objDbCondData.GetServerTime(), PKG, "投入", LotNo, SHOTNum, sumSHOTNum)
        szSql &= ")"

        DBacs.ExecuteUpdateSql(szSql, -1)
    End Sub

    Public Function getGroupSum(EquipNo As String) As Integer
        Dim rtn As Integer = 0
        Dim szSql As String = ""
        szSql &= "SELECT count(*) groupsum "
        szSql &= "FROM PER.T_Alarm_A51_DieClean "
        szSql &= "WHERE EQUIPNO = '" & EquipNo & "' AND "
        szSql &= "USEFLAG = 1 "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        rtn = dt.Rows(0)("groupsum")
        Return rtn
    End Function

End Class
